<?php

use backend\widgets\Bar;
use backend\grid\CheckboxColumn;
use backend\grid\ActionColumn;
use backend\grid\GridView;
use yii\widgets\Pjax;
use common\libs\Constants;
use backend\models\UserCertification;
use yii\bootstrap\Html;

/* @var $this yii\web\View */
/* @var $searchModel backend\models\search\UserCertificationSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title                   = "用户身份审核";
$this->params['breadcrumbs'][] = "用户身份审核";
?>
<div class="row">
    <div class="col-sm-12">
        <div class="ibox ">
            <?= $this->render('/widgets/_ibox-title') ?>
            <div class="ibox-content">
                <?= Bar::widget() ?>
                <!--                --><? //= $this->render('_search', ['model' => $searchModel]); ?>
                <?php Pjax::begin(['id' => 'pjax']); ?>
                <!--                --><?php //var_dump($searchModel)?>
                <?= GridView::widget([
                    'dataProvider' => $dataProvider,
                    'filterModel'  => $searchModel,
                    'columns'      => [
                        ['class' => CheckboxColumn::className()],

//                        'id',
                        [
                            'attribute' => 'uid',
                            'filter'    => false,
                            'label'     => "用户id",
                            'width'     => "10px"
                        ],
                        [
                            'attribute' => 'username',
                            'label'     => "用户名",
                            'value'     => function ($model) {
                                /**
                                 * @var \backend\models\UserCertification $model
                                 */
                                return $model->u->username;
                            }
                        ],
                        [
                            'attribute' => 'type',
                            'filter'    => Constants::getCertificationType(),
                            'value'     => function ($model) {
                                return Constants::getCertificationType($model->type);
                            }
                        ],
                        'real_name',
                        'id_card',
                        // 'phone',
                        // 'token',
                        [
                            'attribute' => 'img',
                            'filter'    => false,
//                            'sort'=>false,
                            'format'    => [
                                'image',
                                [
                                    'width' => "150xp"
                                ]
                            ],
                            'value'     => function ($model) {
                                /**
                                 * @var \backend\models\UserCertification $model
                                 * @var \feehi\cdn\TargetAbstract $cdn
                                 */
                                $cdn = Yii::$app->get('cdn');

                                return $cdn->getCdnUrl($model->img0->image);
                            },
                            'width'     => '100px'
                        ],
                        // 'notify',
//                        [
//                            'attribute' => 'status',
//                            'filter'    => Constants::getCertificationStatus(),
//                            'value'     => function ($model) {
//                                return Constants::getCertificationStatus($model->status);
//                            }
//                        ],
                        [
                            'label'     => '审核',
                            'format'    => 'raw',
                            'attribute' => 'status',
                            'filter'    => Constants::getCertificationStatus(),
                            'value'     => function ($model) {
                                return Html::a("通过",
                                        ['update', 'id' => $model['id']],
                                        [
                                            'class'        => 'btn btn-xs btn-rounded ' . ($model->status == UserCertification::SUCCESS_STATUS ? 'btn-info' : 'btn-default'),
                                            'data-confirm' => $model->status == UserCertification::SUCCESS_STATUS ? '确定审核通过?' : '确定更改为待审核状态?',
                                            'data-method'  => 'post',
                                            'data-pjax'    => '0',
                                            'data-params'  => [
                                                $model->formName() . '[status]' => $model->status != UserCertification::SUCCESS_STATUS ? UserCertification::SUCCESS_STATUS : UserCertification::WAIT_STATUS
                                            ],
                                        ])
                                       . '&nbsp' .
                                       Html::a("不通过",
                                           ['update', 'id' => $model['id']], [
                                               'class'        => 'btn btn-xs btn-rounded ' . ($model->status == UserCertification::ERROR_STATUS ? 'btn-danger' : 'btn-default'),
                                               'data-confirm' => $model->status != UserCertification::ERROR_STATUS ? '确定审核不通过?' : '确定更改为待审核状态?',
                                               'data-method'  => 'post',
                                               'data-pjax'    => '0',
                                               'data-params'  => [
                                                   $model->formName() . '[status]' => $model->status != UserCertification::ERROR_STATUS ? UserCertification::ERROR_STATUS : UserCertification::WAIT_STATUS
                                               ]
                                           ]);
                            }
                        ],
                        [
                            'class'     => \backend\grid\DataColumn::className(),
                            'attribute' => 'created_at',
                            'format'    => "datetime",
//                            'width'     => '30px'
                        ],
                        // 'updated_at',

                        [
                            'class'    => ActionColumn::className(),
                            'template' => '{view-layer}',
                            'width'    => '50px'
                        ],
                    ],
                ]); ?>
                <?php Pjax::end(); ?>
            </div>
        </div>
    </div>
</div>
